package de.koller.worlders.engine.entity;

import de.koller.oceanFramework.OceanException;
import de.koller.oceanFramework.math.ROVec;
import de.koller.oceanFramework.math.Vec;
import de.koller.worlders.WSea;

public class AABBObject extends WSea implements IAABB {
	private final Vec position;
	private final Vec size;
	
	private Vec visualPos;
	private Vec visualSize;
	private Vec visualRotationOffset;
	private float visualRotation = 0;
	
	private boolean mirrorX, mirrorY;
	private int textureColor = 0xffffffff;
	private IRenderable visual = null;

	public AABBObject( float x, float y, float w, float h ) {
		this.position = new Vec( x, y );
		this.size = new Vec( w, h );
		
		this.visualPos = this.position;
		this.visualSize = this.size;
		this.setVisualRotationOffset( null );
	}
	
	public AABBObject() {
		this.position = null;
		this.size = null;
	}

	public void setVisual( IRenderable visual ) {
		this.visual = visual;
	}

	@Override
	public Vec getPosition() {
		if( position == null )
			throw new OceanException( "Muss überschrieben werden wenn von Knoten abgeleitet." );
		return position;
	}

	@Override
	public Vec getSize() {
		if( size == null )
			throw new OceanException( "Muss überschrieben werden wenn von Knoten abgeleitet." );
		return size;
	}

	public Vec getCentre() {
		float x = this.getPosition().getXf() + this.getSize().getXf()*0.5f;
		float y = this.getPosition().getYf() + this.getSize().getYf()*0.5f;
		return new Vec( x, y );
	}

	public boolean isMirrorX() {
		return mirrorX;
	}

	public void setMirrorX( boolean mirrorX ) {
		this.mirrorX = mirrorX;
	}

	public boolean isMirrorY() {
		return mirrorY;
	}

	public void setMirrorY( boolean mirrorY ) {
		this.mirrorY = mirrorY;
	}

	public IRenderable getVisual() {
		return visual;
	}

	public int getTextureColor() {
		return textureColor;
	}

	public void setTextureColor( int textureColor ) {
		this.textureColor = textureColor;
	}

	public float getVisualRotation() {
		return visualRotation;
	}

	public void setVisualRotation( float rotation ) {
		this.visualRotation = rotation;
	}

	public void setVisualPos( Vec visualPos ) {
		if( visualPos == null )
			this.visualPos = position;
		else
			this.visualPos = visualPos;
	}

	public void setVisualSize( Vec visualSize ) {
		if( visualSize == null )
			this.visualSize = size;
		else
			this.visualSize = visualSize;
	}

	public ROVec getVisualPos() {
		return visualPos;
	}

	public ROVec getVisualSize() {
		return visualSize;
	}

	public ROVec getVisualRotationOffset() {
		return visualRotationOffset;
	}

	public void setVisualRotationOffset( Vec visualRotationOffset ) {
		if( visualRotationOffset == null )
			this.visualRotationOffset = new Vec( this.size.getXf()*.5f, this.size.getYf()*.5f );
		else
			this.visualRotationOffset = visualRotationOffset;
	}

	
}
